package ai.leinao.notify.webhook;

import ai.leinao.notify.core.NotifyProperties;
import cn.hutool.http.Method;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * http 属性
 *
 * @author zhong.wang
 * @date 2025/7/11
 */
@Getter
@Setter
public class WebHookProperties {
    /**
     *  url
     */
    private String url;

    /**
     *  请求方式
     */
    private Method method = Method.POST;

    /**
     *  请求头
     */
    private Map<String, String> headers;

    /**
     * 创建 http 属性
     * @param properties
     * @return
     */
    public static WebHookProperties of(NotifyProperties properties) {
        WebHookProperties webHookProperties = new WebHookProperties();
        webHookProperties.setUrl(properties.getConfiguration().get("url").toString());
        webHookProperties.setMethod(Method.valueOf(properties.getConfiguration().get("method").toString()));
        webHookProperties.setHeaders((Map<String, String>) properties.getConfiguration().get("headers"));
        return webHookProperties;
    }
}
